(function(){"use strict";BX.namespace("BX.UI");BX.UI.AccessRights=function(t){t=t||{};this.options=t;this.renderTo=t.renderTo;this.buttonPanel=BX.UI.ButtonPanel||null;this.layout={container:null};this.component=t.component?t.component:null;this.actionSave=t.actionSave?t.actionSave:"save";this.actionDelete=t.actionDelete?t.actionDelete:"delete";this.actionLoad=t.actionLoad?t.actionLoad:"load";this.mode=t.mode?t.mode:"ajax";this.openPopupEvent=t.openPopupEvent?t.openPopupEvent:null;this.popupContainer=t.popupContainer?t.popupContainer:null;this.additionalSaveParams=t.additionalSaveParams?t.additionalSaveParams:null;this.loadParams=t.loadParams?t.loadParams:null;this.loader=null;this.timer=null;this.initData();if(t.userGroups){this.userGroups=t.userGroups}if(t.accessRights){this.accessRights=t.accessRights}this.isRequested=false;this.loadData();this.bindEvents()};BX.UI.AccessRights.prototype={bindEvents:function(){BX.addCustomEvent("BX.UI.AccessRights.ColumnItem:updateRole",this.updateRole.bind(this));BX.addCustomEvent("BX.UI.AccessRights.ColumnItem:accessOn",this.updateAccessRight.bind(this));BX.addCustomEvent("BX.UI.AccessRights.ColumnItem:accessOff",this.updateAccessRight.bind(this));BX.addCustomEvent("BX.UI.AccessRights.ColumnItem:update",this.adjustButtonPanel.bind(this));BX.addCustomEvent("BX.UI.AccessRights.ColumnItem:addRole",this.addUserGroup.bind(this));BX.addCustomEvent("BX.UI.AccessRights.ColumnItem:addRole",this.addRoleColumn.bind(this));BX.addCustomEvent("BX.UI.AccessRights.ColumnItem:copyRole",this.addRoleColumn.bind(this));BX.addCustomEvent("BX.UI.AccessRights.ColumnItem:copyRole",this.addUserGroup.bind(this));BX.addCustomEvent("BX.UI.AccessRights.ColumnItem:removeRole",this.removeRoleColumn.bind(this));BX.addCustomEvent("BX.UI.AccessRights.ColumnItem:removeRole",this.adjustButtonPanel.bind(this));BX.addCustomEvent("BX.Main.SelectorV2:onGetEntityTypes",this.onGetEntityTypes.bind(this))},initData:function(){this.accessRights=[];this.userGroups=[];this.accessRightsSections=[];this.headSection=null;this.members=[];this.columns=[]},fireEventReset:function(){BX.onCustomEvent(window,"BX.UI.AccessRights:reset",this)},fireEventRefresh:function(){BX.onCustomEvent(window,"BX.UI.AccessRights:refresh",this)},getButtonPanel:function(){return this.buttonPanel},showNotification:function(t){BX.UI.Notification.Center.notify({content:t,position:"top-right",autoHideDelay:3e3})},sendActionRequest:function(){if(this.isRequested){return}this.isRequested=true;this.timer=setTimeout(function(){this.blockGrid()}.bind(this),1e3);var t=false;var e=[];for(var i=0;i<this.userGroups.length;i++){if(this.userGroups[i].id==0){t=true}e.push({accessCodes:this.userGroups[i].accessCodes,id:this.userGroups[i].id,title:this.userGroups[i].title,type:this.userGroups[i].type,accessRights:this.userGroups[i].accessRights})}BX.ajax.runComponentAction(this.component,this.actionSave,{mode:this.mode,data:{userGroups:e,parameters:this.additionalSaveParams}}).then(function(){if(t){this.reloadGrid()}this.isRequested=false;this.showNotification(BX.message("JS_UI_ACCESSRIGHTS_STTINGS_HAVE_BEEN_SAVED"));this.unBlockGrid();this.fireEventRefresh();setTimeout(function(){this.adjustButtonPanel()}.bind(this));clearTimeout(this.timer);this.buttonPanel.getContainer().querySelector(".ui-btn-wait").classList.remove("ui-btn-wait")}.bind(this),function(){this.isRequested=false;this.showNotification("Error message");this.unBlockGrid();clearTimeout(this.timer);this.buttonPanel.getContainer().querySelector(".ui-btn-wait").classList.remove("ui-btn-wait")}.bind(this));BX.onCustomEvent(window,"BX.UI.AccessRights:preservation",this)},lock:function(){this.getMainContainer().classList.add("--lock")},unlock:function(){this.getMainContainer().classList.remove("--lock")},deleteActionRequest:function(t){if(this.isRequested){return}this.isRequested=true;this.timer=setTimeout(function(){this.blockGrid()}.bind(this),1e3);BX.ajax.runComponentAction(this.component,this.actionDelete,{mode:this.mode,data:{roleId:t}}).then(function(){this.isRequested=false;this.showNotification(BX.message("JS_UI_ACCESSRIGHTS_ROLE_REMOVE"));this.unBlockGrid();clearTimeout(this.timer)}.bind(this),function(){this.isRequested=false;this.showNotification("Error message");this.unBlockGrid();clearTimeout(this.timer)}.bind(this))},reloadGrid:function(){this.initData();BX.ajax.runComponentAction(this.component,this.actionLoad,{mode:this.mode,data:{parameters:this.loadParams}}).then(function(t){if(t.data["ACCESS_RIGHTS"]&&t.data["USER_GROUPS"]){this.accessRights=t.data.ACCESS_RIGHTS;this.userGroups=t.data.USER_GROUPS;this.loadData();this.draw()}this.unBlockGrid()}.bind(this),function(){this.unBlockGrid()}.bind(this))},blockGrid:function(){var t=this.layout.container.getBoundingClientRect().top<0?"0":this.layout.container.getBoundingClientRect().top;this.layout.container.classList.add("ui-access-rights-block");this.layout.container.style.height="calc(100vh - "+t+"px)";setTimeout(function(){this.layout.container.style.height="calc(100vh - "+t+"px)"}.bind(this));var e=this;this.getLoader().then(function(){e.loader.show()})},unBlockGrid:function(){this.layout.container.classList.remove("ui-access-rights-block");this.layout.container.style.height=null;var t=this;this.getLoader().then(function(){t.loader.hide()})},loadLoaderExtension:function(){return new Promise(function(t){if(BX.Loader){return t()}BX.loadExt("main.loader").then(function(){t()})})},getLoader:function(){var t=this;return new Promise(function(e){t.loadLoaderExtension().then(function(){if(!t.loader){t.loader=new BX.Loader({target:t.layout.container})}e()})})},removeRoleColumn:function(t){this.headSection.removeColumn(t.data);this.accessRightsSections.map(function(e){e.removeColumn(t.data)});var e=this.userGroups.indexOf(t.data.userGroup);this.userGroups.splice(e,1);var i=t.data.userGroup.id;this.deleteActionRequest(i)},addRoleColumn:function(t){if(!t){return}var e=this.accessRightsSections;for(var i=0;i<e.length;i++){t.headSection=false;t.newColumn=true;e[i].addColumn(t);e[i].scrollToRight(e[i].getColumnsContainer().scrollWidth-e[i].getColumnsContainer().offsetWidth,"stop")}t.headSection=true;t.newColumn=true;this.headSection.addColumn(t)},addUserGroup:function(t){t=t||{};this.userGroups.push(t)},updateRole:function(t){var e=this.userGroups.indexOf(t.data.userGroup);if(e>=0){this.userGroups[e].title=t.data.text}},adjustButtonPanel:function(){var t=this.getMainContainer().querySelectorAll(".ui-access-rights-column-item-changer-on");var e=this.getMainContainer().querySelectorAll(".ui-access-rights-column-new");var i=this.getMainContainer().querySelectorAll(".ui-access-rights-members-item-new");if(t.length>0||e.length>0||i.length>0){this.buttonPanel.show()}else{this.buttonPanel.hide()}},updateAccessRight:function(t){var e=t.data;var i=this.userGroups[this.userGroups.indexOf(e.userGroup)];var s=e.access.id;for(var n=0;n<i.accessRights.length;n++){var o=i.accessRights[n];if(o.id===s){o.value==="0"?o.value="1":o.value="0";return}}i.accessRights.push({id:s,value:e.switcher.checked?"1":"0"})},loadData:function(){this.accessRights.map(function(t,e){t.id=e;this.accessRightsSections.push(this.addSection(t))}.bind(this))},getColumns:function(){return this.columns},getSections:function(){return this.accessRightsSections},getUserGroups:function(){this.userGroups.forEach(function(t){if(t.accessCodes){for(var e in t.members){t.accessCodes[e]=t.members[e].type}}});return this.userGroups},getHeadSection:function(){if(!this.headSection){this.headSection=new BX.UI.AccessRights.Section({headSection:true,userGroups:this.userGroups,grid:this})}return this.headSection},addSection:function(t){t=t||{};return new BX.UI.AccessRights.Section({id:t.id,title:t.sectionTitle,rights:t.rights?t.rights:[],grid:this})},getSection:function(){return BX.create("div",{props:{className:"ui-access-rights-section"}})},getMainContainer:function(){if(!this.layout.container){this.layout.container=BX.create("div",{props:{className:"ui-access-rights"}})}return this.layout.container},draw:function(){var t=document.createDocumentFragment();t.appendChild(this.getHeadSection().render());this.getSections().map(function(e){t.appendChild(e.render())}.bind(this));this.layout.container=null;this.getMainContainer().appendChild(t);this.renderTo.innerHTML="";this.renderTo.appendChild(this.getMainContainer());this.afterRender()},afterRender:function(){this.getHeadSection().adjustEars();this.getSections().map(function(t){t.adjustEars()})},onMemberSelect:function(t){var e=BX.UI.AccessRights.buildOption(t);if(!e){return}if(t.state==="select"){BX.onCustomEvent("BX.UI.AccessRights:addToAccessCodes",e)}},onMemberUnselect:function(t){var e=BX.UI.AccessRights.buildOption(t);if(!e){return}BX.onCustomEvent("BX.UI.AccessRights:removeFromAccessCodes",e)},onGetEntityTypes:function(){var t=BX.Main.selectorManagerV2.controls;var e=t[Object.keys(t)[0]];e.entityTypes.USERGROUPS={options:{enableSearch:"Y",searchById:"Y",addTab:"Y",returnItemUrl:e.getOption("returnItemUrl")=="N"?"N":"Y"}}}};BX.UI.AccessRights.buildOption=function(t){var e=BX.Main.selectorManagerV2.controls;var i=e[Object.keys(e)[0]].selectorInstance;var s="bx-data-column-id";var n=i.bindOptions.node;if(!n.hasAttribute(s)||typeof t.item==="undefined"){return false}var o=n.getAttribute(s);var a=t.item.id;var r=t.entityType;var c={};c[a]=r;return{accessCodes:c,columnId:o,item:t.item}}})();
//# sourceMappingURL=grid.map.js